package com.cloudbroker.openapi.manage.controller;

import com.alibaba.fastjson.JSON;
import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.transaction.back.CombineApplyBack;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.transaction.back.CombineSummaryList;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.transaction.vo.CombineCreateForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.transaction.vo.CombineFocusForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.transaction.vo.CombineSummaryQryForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.t2service.transaction.CombineT2BizService;
import com.cloudbroker.bcs.platform.ltb.common.ext.annotation.SaveLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cloudbroker.bcs.platform.ltb.common.util.RequestUtil.getSingleParameterMapForBody;

/**
 * Created by tianrui on 2016/7/22.
 */


@Controller
public class CombineController {

    @Resource
    private CombineT2BizService combineT2BizService;

    /**
     * 组合申请
     * */
    @ResponseBody
    @RequestMapping("/middle_combine_apply")
    @SaveLog(remark = "组合申请")
    public CombineApplyBack CobineApply(HttpServletRequest request, String jsonpcallback){
        CombineCreateForm form = getSingleParameterMapForBody(request , CombineCreateForm.class);
        return VOUtil.setJsonpResult(combineT2BizService.CombineApply(form), jsonpcallback);
    }

    /**
     * 组合收藏
     * */
    @ResponseBody
    @RequestMapping("/middle_combine_collect")
    @SaveLog(remark = "组合关注")
    public HSBCPSBackVO CombineFocus(HttpServletRequest request, String jsonpcallback){
        CombineFocusForm form = getSingleParameterMapForBody(request , CombineFocusForm.class);
        return VOUtil.setJsonpResult(combineT2BizService.CombineFocus(form), jsonpcallback);
    }

    /**
     * 组合收藏取消
     * */
    @ResponseBody
    @RequestMapping("/middle_combine_collect_cancel")
    @SaveLog(remark = "组合关注取消")
    public HSBCPSBackVO CombineFocusCancel (HttpServletRequest request, String jsonpcallback){
        CombineFocusForm form = getSingleParameterMapForBody(request , CombineFocusForm.class);
        return VOUtil.setJsonpResult(combineT2BizService.CombineFocusCancel(form), jsonpcallback);
    }

    /**
     * 组合概要信息查询
     * */
    @ResponseBody
    @RequestMapping("/combine_summary_qry")
    @SaveLog(remark = "组合概要信息查询")
    public CombineSummaryList CombineSummaryQuery (HttpServletRequest request, String jsonpcallback){
        CombineSummaryQryForm form = getSingleParameterMapForBody(request , CombineSummaryQryForm.class);
        return VOUtil.setJsonpResult(combineT2BizService.CombineSummaryQuery(form), jsonpcallback);
    }

//    public static void main(String[] args){
//        Map parent_map = new HashMap();
//
//        List<Map> l = new ArrayList();
//        Map m1 = new HashMap();
//        m1.put("combi_code","123");
//        l.add(m1);
//        parent_map.put("data_list",l);
//        System.out.println(JSON.toJSON(parent_map));
//    }

}
